#include "config.h"
#include <stdio.h>

#define P2_IN_SIZE     10
#define P2_KER_SIZE    2
#define P2_OUT_SIZE    5

// 第2层池化
void maxpool2d_i10_k2_o5(
    dtype d_in[P2_IN_SIZE][P2_IN_SIZE],
    dtype d_out[P2_OUT_SIZE][P2_OUT_SIZE]){
    
    for (int i = 0; i < P2_OUT_SIZE; i++){
        for (int j = 0; j < P2_OUT_SIZE; j++){
            d_out[i][j] = Q4_12_MAX(Q4_12_MAX(d_in[(i<<1)][(j<<1)], d_in[(i<<1)][(j<<1) + 1]),
                            Q4_12_MAX(d_in[(i<<1) + 1][(j<<1)], d_in[(i<<1) + 1][(j<<1) + 1]));
            // printf("%4d,%4d,%4d,%4d\n", d_in[(i<<1)][(j<<1)], d_in[(i<<1)][(j<<1) + 1], d_in[(i<<1) + 1][(j<<1)], d_in[(i<<1) + 1][((j<<1)) + 1]);
        }
    }
}

/* 测试代码 */
dtype d_in[P2_IN_SIZE][P2_IN_SIZE];
dtype d_out[P2_OUT_SIZE][P2_OUT_SIZE];

void data_pre(){
    for (int i = 0; i < P2_IN_SIZE; i++){
        for (int j = 0; j < P2_IN_SIZE; j++){
            d_in[i][j] = i * P2_IN_SIZE + j;
            printf("%4d,", d_in[i][j]);
        }
        printf("\n");
    }
}

void data_print(){
    for (int i = 0; i < P2_OUT_SIZE; i++){
        for (int j = 0; j < P2_OUT_SIZE; j++){
            d_in[i][j] = i * P2_OUT_SIZE + j;
            printf("%4d,", d_out[i][j]);
        }
        printf("\n");
    }
}

int main(int argc, char const *argv[])
{
    data_pre();
    maxpool2d_i10_k2_o5(d_in, d_out);
    printf("\n");
    data_print();
    return 0;
}
